﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GalleryCommon;

namespace GalleryWeb
{
    public partial class GalleryApp : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] == null)
            {
                Response.Redirect("login.aspx");
            }
            User user = (User)Session["User"];
            LabelUser.Text = "Welcome, " + user.Username;

            ImageButton imgexit = new ImageButton();
            imgexit.ImageUrl = "Icons/logout.png";
            imgexit.Attributes.Add("class", "IconStyle");
            imgexit.Click += new ImageClickEventHandler(LogOut_Click);
            cellright.Controls.Add(imgexit);

            if (Page.TemplateControl.AppRelativeVirtualPath == "~/MainView.aspx")
            {
                ImageButton imgbtn = new ImageButton();
                imgbtn.ImageUrl = "Icons/albumview.png";
                imgbtn.Attributes.Add("class", "IconStyle");
                imgbtn.Click += new ImageClickEventHandler(BackToAlbumView);
                cellmid.Controls.Add(imgbtn);
            }
            if (Page.TemplateControl.AppRelativeVirtualPath == "~/Image.aspx")
            {
                ImageButton imgbtn = new ImageButton();
                imgbtn.ImageUrl = "Icons/albumview.png";
                imgbtn.Attributes.Add("class", "IconStyle");
                imgbtn.Click += new ImageClickEventHandler(BackToAlbumView);
                cellmid.Controls.Add(imgbtn);
                ImageButton imgbtn2 = new ImageButton();
                imgbtn2.ImageUrl = "Icons/3x3-grid.png";
                imgbtn2.Attributes.Add("class", "IconStyle");
                imgbtn2.Click += new ImageClickEventHandler(BackToMainView);
                cellmid.Controls.Add(imgbtn2);
            }

        }
        protected void BackToAlbumView(object sender, EventArgs e)
        {
            Response.Redirect("AlbumView.aspx");
        }
        protected void BackToMainView(object sender, EventArgs e)
        {
            Response.Redirect("MainView.aspx");
        }

        protected void LogOut_Click(object sender, EventArgs e)
        {
            Session["User"] = null;
            Response.Redirect("Login.aspx");
        }
    }
}